<?php

class Pagination {

	private $page_current;
	private $page_limit;
	private $page_count;

	public function __construct()
	{
		$this->page_current = 1;
		$this->page_limit   = 15;
		$this->page_count   = 1;
	}

	public function setCurrentPage($current)
	{
		if(false == $current)
		{
			$current = 1;
		}

		$this->page_current = abs($current);

		return true;
	}

	public function setPerPage($perpage)
	{
		$this->page_limit = $perpage;

		return true;
	}

	public function setPageCount($records)
	{
		$this->page_count = ceil($records / $this->page_limit);

		if(false == $this->page_count)
		{
			$this->page_count = 1;
		}

		return true;
	}

	public function getPageLimits()
	{
		return array('offset' => $this->page_limit * ($this->page_current - 1), 'limit' => $this->page_limit);

	}

	public function getPageCount()
	{
		return $this->page_count;
	}

	public function getCurrentPage()
	{
		if($this->page_current > $this->page_count)
		{
			$this->setCurrentPage($this->page_count);

			return $this->page_current;
		}

		return $this->page_current;
	}
}

?>